package com.sky.controller.user;


import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户端购物车相关接口")
@Slf4j
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 添加购物车模块
     * @param shoppingCartDTO
     * @return
     */
    @ApiOperation("添加购物车")
    @PostMapping("/add")
    public Result<String> addCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("添加购物车商品信息为：{}",shoppingCartDTO);
        shoppingCartService.addCart(shoppingCartDTO);
        return Result.success();
    }
    /**
     * 查看购物车
     * @return
     */
    @ApiOperation("查看购物车")
    @GetMapping("/list")
    public Result<List<ShoppingCart>> getShoppingCartList(){
        List<ShoppingCart> shoppingCartList = shoppingCartService.getShoppingCartList();
        return Result.success(shoppingCartList);
    }
    /**
     *删除一个购物车的商品
     * @param shoppingCartDTO
     * @return
     */
    @ApiOperation("删除单个购物车商品")
    @PostMapping("/sub")
    public Result<String> subCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("删除购物车商品信息为：{}",shoppingCartDTO);
        shoppingCartService.subCart(shoppingCartDTO);
        return Result.success();
    }
    /**
     * 清空购物车
     * @return
     */
    @ApiOperation("清空购物车")
    @DeleteMapping("/clean")
    public Result<String> cleanCart(){
        shoppingCartService.cleanCart();
        return Result.success();
    }
}
